/**
 * 生成系统内各种id, 包括cardId, orderId等
 * Created by dongchen on 16/5/12.
 */
var moment = require('moment');
var _ = require('lodash');
var commonUtils = require('./commonUtils');

var orderSeq = 0;

function cardId(openTime, seq){
    seq = (+seq % 100000).toFixed(0);
    var prefix = moment(openTime).format('YYMMDD');
    var suffix = _.padStart(String(seq), 5, '0');
    return prefix + suffix;
}

function orderId(openId){
    var prefix = moment().format('YYMMDDHHmmss');
    var body = openId.slice(0, 4);
    var seq = (orderSeq % 10000).toFixed(0);
    orderSeq++;
    var suffix = _.padStart(String(seq), 4, '0');
    return prefix + body + suffix;
}

function cardPwd(){
    return commonUtils.randomStr(6);
}

function nonceStr (){
    return commonUtils.randomStr(16);
}

module.exports = {
    cardId : cardId,
    orderId : orderId,
    cardPwd : cardPwd,
    nonceStr : nonceStr
};